<?php

class AgbookController extends AController
{
   
	public function actionIndex()
	{
		$model=new Gbook('search');
        
		$model->unsetAttributes();  // clear any default values
		if(isset($_GET['Gbook']))
			$model->attributes=$_GET['Gbook'];

		$this->render('index',array(
		                  	'model'=>$model,
	                   	));
	}
    
    
    
	public function actionUpdate($id)
	{
		$model=$this->loadModel($id);

		// Uncomment the following line if AJAX validation is needed
		// $this->performAjaxValidation($model);

		if(isset($_POST['Gbook']))
		{
			$model->attributes=$_POST['Gbook'];
			if($model->save())
				$this->redirect(array('index','id'=>$model->id));
		}

		$this->render('update',array(
		                  	'model'=>$model,
	                       	));
	}
    


	public function actionDelete($id)
	{
		$this->loadModel($id)->delete();

		// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
		if(!isset($_GET['ajax']))
			$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('index'));
	}
    
    
  
	public function loadModel($id)
	{
		$model=Gbook::model()->findByPk($id);
		if($model===null)
			throw new CHttpException(404,'Запрашиваемая страница не найдена');
		return $model;
	}


	protected function performAjaxValidation($model)
	{
		if(isset($_POST['ajax']) && $_POST['ajax']==='gbook-form')
		{
			echo CActiveForm::validate($model);
			Yii::app()->end();
		}
	} 
     
    
}  // end class